<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>hishion blog</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog/img/favicon.ico">
    <meta name="description" content="web front-end development engineer">
    <meta name="title" content="hishion blog">
    <meta name="keywords" content="小程序,Vue,uni-app,LESS/SCSS,Git">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.85454e8d.css" as="style"><link rel="preload" href="/blog/assets/js/app.17d93a93.js" as="script"><link rel="preload" href="/blog/assets/js/2.d5810a70.js" as="script"><link rel="preload" href="/blog/assets/js/7.7a113c37.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.a2c8b9d7.js"><link rel="prefetch" href="/blog/assets/js/11.6316d0fd.js"><link rel="prefetch" href="/blog/assets/js/12.927e97fe.js"><link rel="prefetch" href="/blog/assets/js/13.5647b041.js"><link rel="prefetch" href="/blog/assets/js/14.2ae9363a.js"><link rel="prefetch" href="/blog/assets/js/15.00f0b12c.js"><link rel="prefetch" href="/blog/assets/js/16.cf70fbc0.js"><link rel="prefetch" href="/blog/assets/js/17.03f65a2a.js"><link rel="prefetch" href="/blog/assets/js/18.eab9c888.js"><link rel="prefetch" href="/blog/assets/js/19.41e2fb9c.js"><link rel="prefetch" href="/blog/assets/js/20.a81ff0d7.js"><link rel="prefetch" href="/blog/assets/js/21.8f4e6ef9.js"><link rel="prefetch" href="/blog/assets/js/22.33273307.js"><link rel="prefetch" href="/blog/assets/js/23.b9ccad42.js"><link rel="prefetch" href="/blog/assets/js/24.925b6f8f.js"><link rel="prefetch" href="/blog/assets/js/25.09121221.js"><link rel="prefetch" href="/blog/assets/js/26.93b4179f.js"><link rel="prefetch" href="/blog/assets/js/27.248627a6.js"><link rel="prefetch" href="/blog/assets/js/28.a76943a2.js"><link rel="prefetch" href="/blog/assets/js/29.56872daa.js"><link rel="prefetch" href="/blog/assets/js/3.c69e6cb7.js"><link rel="prefetch" href="/blog/assets/js/30.175b2658.js"><link rel="prefetch" href="/blog/assets/js/31.d027670c.js"><link rel="prefetch" href="/blog/assets/js/32.040794e0.js"><link rel="prefetch" href="/blog/assets/js/33.dd9eea2e.js"><link rel="prefetch" href="/blog/assets/js/34.2b31e291.js"><link rel="prefetch" href="/blog/assets/js/35.009bbce8.js"><link rel="prefetch" href="/blog/assets/js/36.ecb36989.js"><link rel="prefetch" href="/blog/assets/js/37.282a8534.js"><link rel="prefetch" href="/blog/assets/js/38.e29d954d.js"><link rel="prefetch" href="/blog/assets/js/39.e071deb9.js"><link rel="prefetch" href="/blog/assets/js/4.20ff38eb.js"><link rel="prefetch" href="/blog/assets/js/40.e30e040e.js"><link rel="prefetch" href="/blog/assets/js/41.f9beaf4c.js"><link rel="prefetch" href="/blog/assets/js/42.631fa7df.js"><link rel="prefetch" href="/blog/assets/js/43.de052ada.js"><link rel="prefetch" href="/blog/assets/js/44.b9d90c8b.js"><link rel="prefetch" href="/blog/assets/js/45.9edc6da4.js"><link rel="prefetch" href="/blog/assets/js/46.43221d60.js"><link rel="prefetch" href="/blog/assets/js/47.70bd2046.js"><link rel="prefetch" href="/blog/assets/js/48.f2da250c.js"><link rel="prefetch" href="/blog/assets/js/49.db6466ad.js"><link rel="prefetch" href="/blog/assets/js/5.413bc4a0.js"><link rel="prefetch" href="/blog/assets/js/50.465c1401.js"><link rel="prefetch" href="/blog/assets/js/51.25711c0b.js"><link rel="prefetch" href="/blog/assets/js/52.c3dd4c01.js"><link rel="prefetch" href="/blog/assets/js/53.c398474b.js"><link rel="prefetch" href="/blog/assets/js/54.1ff939f2.js"><link rel="prefetch" href="/blog/assets/js/55.d00053e3.js"><link rel="prefetch" href="/blog/assets/js/56.4978060f.js"><link rel="prefetch" href="/blog/assets/js/57.b9b8c161.js"><link rel="prefetch" href="/blog/assets/js/58.d67ad12f.js"><link rel="prefetch" href="/blog/assets/js/59.3a1f358e.js"><link rel="prefetch" href="/blog/assets/js/6.747c84d7.js"><link rel="prefetch" href="/blog/assets/js/60.7b70acc9.js"><link rel="prefetch" href="/blog/assets/js/61.43c54fc8.js"><link rel="prefetch" href="/blog/assets/js/62.d27744a0.js"><link rel="prefetch" href="/blog/assets/js/63.73378bfc.js"><link rel="prefetch" href="/blog/assets/js/64.060c996e.js"><link rel="prefetch" href="/blog/assets/js/65.747c9a84.js"><link rel="prefetch" href="/blog/assets/js/66.2a577ef9.js"><link rel="prefetch" href="/blog/assets/js/67.94620d6a.js"><link rel="prefetch" href="/blog/assets/js/68.3cf29532.js"><link rel="prefetch" href="/blog/assets/js/69.9e992128.js"><link rel="prefetch" href="/blog/assets/js/70.0bf5d79a.js"><link rel="prefetch" href="/blog/assets/js/71.3c940d64.js"><link rel="prefetch" href="/blog/assets/js/72.b39fd551.js"><link rel="prefetch" href="/blog/assets/js/73.b22cb822.js"><link rel="prefetch" href="/blog/assets/js/74.f06bc4d1.js"><link rel="prefetch" href="/blog/assets/js/75.b7bdb0f0.js"><link rel="prefetch" href="/blog/assets/js/76.1dab014e.js"><link rel="prefetch" href="/blog/assets/js/77.7edba438.js"><link rel="prefetch" href="/blog/assets/js/8.eb2c369b.js"><link rel="prefetch" href="/blog/assets/js/9.8d45fb33.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.85454e8d.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><!----> <span class="site-name">hishion blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文章" class="dropdown-title"><span class="title">文章</span> <span class="arrow down"></span></button> <button type="button" aria-label="文章" class="mobile-dropdown-title"><span class="title">文章</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/basic/" class="nav-link">
  前端基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/mp/" class="nav-link">
  小程序
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/" class="nav-link">
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/blog/uni/life.html" class="nav-link">
  uni-app
</a></li><li class="dropdown-item"><!----> <a href="/blog/scss/" class="nav-link">
  SCSS/LESS
</a></li><li class="dropdown-item"><!----> <a href="/blog/git/" class="nav-link router-link-active">
  Git
</a></li><li class="dropdown-item"><!----> <a href="/blog/standard/" class="nav-link">
  前端编码规范
</a></li><li class="dropdown-item"><!----> <a href="/blog/tool/" class="nav-link">
  工具
</a></li><li class="dropdown-item"><!----> <a href="/blog/http/" class="nav-link">
  网络
</a></li><li class="dropdown-item"><!----> <a href="/blog/linux/" class="nav-link">
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/blog/graphql/" class="nav-link">
  GraphQL
</a></li><li class="dropdown-item"><!----> <a href="/blog/other/" class="nav-link">
  其他
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/hishion.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/weixisheng" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文章" class="dropdown-title"><span class="title">文章</span> <span class="arrow down"></span></button> <button type="button" aria-label="文章" class="mobile-dropdown-title"><span class="title">文章</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/basic/" class="nav-link">
  前端基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/mp/" class="nav-link">
  小程序
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/" class="nav-link">
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/blog/uni/life.html" class="nav-link">
  uni-app
</a></li><li class="dropdown-item"><!----> <a href="/blog/scss/" class="nav-link">
  SCSS/LESS
</a></li><li class="dropdown-item"><!----> <a href="/blog/git/" class="nav-link router-link-active">
  Git
</a></li><li class="dropdown-item"><!----> <a href="/blog/standard/" class="nav-link">
  前端编码规范
</a></li><li class="dropdown-item"><!----> <a href="/blog/tool/" class="nav-link">
  工具
</a></li><li class="dropdown-item"><!----> <a href="/blog/http/" class="nav-link">
  网络
</a></li><li class="dropdown-item"><!----> <a href="/blog/linux/" class="nav-link">
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/blog/graphql/" class="nav-link">
  GraphQL
</a></li><li class="dropdown-item"><!----> <a href="/blog/other/" class="nav-link">
  其他
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/hishion.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/weixisheng" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端基础</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>小程序</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>SCSS/LESS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Git知识</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/git/" aria-current="page" class="sidebar-link">Git命令</a></li><li><a href="/blog/git/commit.html" aria-current="page" class="active sidebar-link">Git提交规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/git/commit.html#基本格式" class="sidebar-link">基本格式</a></li><li class="sidebar-sub-header"><a href="/blog/git/commit.html#工具校验" class="sidebar-link">工具校验</a></li><li class="sidebar-sub-header"><a href="/blog/git/commit.html#changelog" class="sidebar-link">CHANGELOG</a></li><li class="sidebar-sub-header"><a href="/blog/git/commit.html#git提交添加表情" class="sidebar-link">git提交添加表情</a></li></ul></li><li><a href="/blog/git/emoji.html" class="sidebar-link">Git emoji</a></li><li><a href="/blog/git/rename.html" class="sidebar-link">分支重命名</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端规范</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>工具</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Linux知识</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>GraphQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>网络知识</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>其他</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><p>社区有多种 Commit message 的写法规范，比较流行的方案是约定式提交规范（Conventional Commits），它受到了<code>Angular</code>提交准则的启发，并在很大程度上以其为依据。</p> <h2 id="基本格式"><a href="#基本格式" class="header-anchor">#</a> 基本格式</h2> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token operator">&lt;</span>type<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token operator">&lt;</span>scope<span class="token operator">&gt;</span><span class="token punctuation">)</span>: <span class="token operator">&lt;</span>subject<span class="token operator">&gt;</span>
// 空一行
<span class="token operator">&lt;</span>body<span class="token operator">&gt;</span>
// 空一行
<span class="token operator">&lt;</span>footer<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>其中，Header 是必需的，Body 和 Footer 可以省略。例如：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>feat: 新增优惠券功能

fix<span class="token punctuation">(</span>coupon-picker.vue<span class="token punctuation">)</span>: 修复优惠券无法选择的问题
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="header"><a href="#header" class="header-anchor">#</a> Header</h4> <ul><li>type 用于说明 commit 的类别，只允许使用下面的标识。</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">/* 主要type */</span>
feat <span class="token comment">// 新功能（feature）</span>
fix <span class="token comment">// 修复bug</span>

<span class="token comment">/* 特殊type */</span>
docs <span class="token comment">// 改动文档内容（documentation）</span>
style <span class="token comment">// 格式（不影响代码运行的变动，去掉空格、缩进等）</span>
refactor <span class="token comment">// 重构（即不是新增功能，也不是修改bug的代码变动）</span>
chore <span class="token comment">// 不修改src或者test的其余修改，构建过程或辅助工具的变动（修改readme，webpack配置）</span>

<span class="token comment">/* 其他type */</span>
pref <span class="token comment">// 提升页面性能</span>
test <span class="token comment">// 增加测试或修改测试</span>
build <span class="token comment">// 影响构建或其他依赖的改动（gulp, npm等）</span>
ci <span class="token comment">// 持续集成的相关改动</span>

<span class="token comment">/* 撤销type */</span>
revert <span class="token comment">// 撤销以前的commit，revert:开头，跟着撤销的header。</span>
<span class="token comment">// 例如：  revert: fix(coupon-picker.vue): 修复优惠券无法选择的问题</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><ul><li>scope 用于说明 commit 影响的范围，比如数据层、控制层、视图层等等，视项目不同而不同。</li> <li>subject 是 commit 目的的简短描述，不超过50个字符。</li></ul> <h4 id="body"><a href="#body" class="header-anchor">#</a> Body</h4> <p>Body 部分是对本次 commit 的详细描述，可以分成多行。</p> <h4 id="footer"><a href="#footer" class="header-anchor">#</a> Footer</h4> <p>Footer 部分只用于两种情况:</p> <ul><li>不兼容变动<br>
如果当前代码与上一个版本不兼容，则 Footer 部分以BREAKING CHANGE开头，后面是对变动的描述、以及变动理由和迁移方法。</li> <li>关闭 Issue<br>
如果当前 commit 针对某个issue，那么可以在 Footer 部分关闭这个 issue 。</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>Closes <span class="token comment">#123, #245, #992</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="工具校验"><a href="#工具校验" class="header-anchor">#</a> 工具校验</h2> <h4 id="commitizen"><a href="#commitizen" class="header-anchor">#</a> <a href="https://github.com/commitizen/cz-cli" target="_blank" rel="noopener noreferrer">Commitizen<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h4> <p>Commitizen是一个撰写合格 Commit message 的工具。全局安装</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">npm</span> i -g commitizen
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>然后在项目目录里面运行命令，使其支持Angular的提交格式规范</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>commitizen init cz-conventional-changelog --save-dev --save-exact
<span class="token comment"># or yarn</span>
commitizen init cz-conventional-changelog --yarn --dev --exact
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>使用：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token function">git</span> cz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><img src="" alt="提交信息"> <img src="/blog/assets/img/git-2.4154b542.png" alt="提交结果"></p> <h4 id="validate-commit-msg"><a href="#validate-commit-msg" class="header-anchor">#</a> <a href="https://github.com/conventional-changelog-archived-repos/validate-commit-msg" target="_blank" rel="noopener noreferrer">validate-commit-msg<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h4> <p>validate-commit-msg 一款Node插件，检查项目的 Commit message 是否符合格式。</p> <ul><li>新建.vcmrc文件</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;types&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;feat&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;fix&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;docs&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;style&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;refactor&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;perf&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;test&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;build&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;ci&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;chore&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;revert&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token property">&quot;scope&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;required&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token property">&quot;allowed&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;*&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;validate&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token property">&quot;multiple&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;warnOnFail&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
  <span class="token property">&quot;maxSubjectLength&quot;</span><span class="token operator">:</span> <span class="token number">100</span><span class="token punctuation">,</span>
  <span class="token property">&quot;subjectPattern&quot;</span><span class="token operator">:</span> <span class="token string">&quot;.+&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;subjectPatternErrorMsg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;subject does not match subject pattern!&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;helpMessage&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;autoFix&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><ul><li>package.json配置</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  ...
  ...
  <span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;validate-commit-msg&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;types&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;feat&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;fix&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;docs&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;style&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;refactor&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;perf&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;test&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;build&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;ci&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;chore&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;revert&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token property">&quot;scope&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;required&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token property">&quot;allowed&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;*&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token property">&quot;validate&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token property">&quot;multiple&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;warnOnFail&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
      <span class="token property">&quot;maxSubjectLength&quot;</span><span class="token operator">:</span> <span class="token number">100</span><span class="token punctuation">,</span>
      <span class="token property">&quot;subjectPattern&quot;</span><span class="token operator">:</span> <span class="token string">&quot;.+&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;subjectPatternErrorMsg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;subject does not match subject pattern!&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;helpMessage&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;autoFix&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><ul><li>ghooks配置</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code> <span class="token function">npm</span> i ghooks --save-dev
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  ...
  <span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;ghooks&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;commit-msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;validate-commit-msg&quot;</span>
    <span class="token punctuation">}</span>
    ...
  <span class="token punctuation">}</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img src="/blog/assets/img/git-3.ecac47a6.png" alt="提交结果"></p> <h2 id="changelog"><a href="#changelog" class="header-anchor">#</a> CHANGELOG</h2> <p>使用 <code>conventional-changelog-cli</code>生成 <code>changelog</code>。全局安装</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">npm</span> <span class="token function">install</span> -g conventional-changelog-cli
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>在需要使用的项目下</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 输出所有changelogs，一般第一次使用</span>
conventional-changelog -p angular -i CHANGELOG.md -s -r <span class="token number">0</span>
<span class="token comment"># 基于先前changelogs添加</span>
conventional-changelog -p angular -i CHANGELOG.md -s
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>参数说明</p> <table><thead><tr><th>配置</th> <th>说明</th></tr></thead> <tbody><tr><td>-i, --infile</td> <td>标记读取changelog的文件</td></tr> <tr><td>-o, --outfile</td> <td>将changelog写入的文件路径，若未指定，打印到输出</td></tr> <tr><td>-s, --same-file</td> <td>输出到跟infile的同一个文件，这样不用传outfile参数</td></tr> <tr><td>-p, --preset</td> <td>使用的预设名称，可选项：angular, atom, codemirror, ember, eslint, express, jquery, jscs, jshint</td></tr> <tr><td>-r, --release-count</td> <td>从最新版本生成多少个版本，传0的话，重新生成所有版本，默认1</td></tr></tbody></table> <h2 id="git提交添加表情"><a href="#git提交添加表情" class="header-anchor">#</a> git提交添加表情</h2> <p>更多查看<a href="./emoji">Git emoji</a></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/blog/git/" class="prev router-link-active">
        Git命令
      </a></span> <span class="next"><a href="/blog/git/emoji.html">
        Git emoji
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/blog/assets/js/app.17d93a93.js" defer></script><script src="/blog/assets/js/2.d5810a70.js" defer></script><script src="/blog/assets/js/7.7a113c37.js" defer></script>
  </body>
</html>
